﻿/*
 * @Autor: PK
 * @Date: 2021/12/27 22:31:SS
 *  终值统计特性	归属项	值
 */

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ShkSimulation.core.dao.statistic.feature {

	public sealed class StatisticInfo : IEnumerable<DataPair> {

		public StatisticInfo(VariableAndHourStatisticKey variableAndHourStatisticName) {
			this.UniqueKey = variableAndHourStatisticName;
		}
		
		public DataPair this[string variableName] {
			get { return Datas[variableName]; }
		}

		public VariableAndHourStatisticKey UniqueKey { get; set; }

		public Dictionary<string, DataPair> Datas { get; set; } = new Dictionary<string, DataPair>();
		
		public DataPair First => Datas == null || Datas.Count == 0? DataPair.Empty : Datas.First().Value;

		public IEnumerator<DataPair> GetEnumerator() {
			List<DataPair> collection = Datas.Values.Where(each => each != DataPair.Empty).ToList();
			return collection.GetEnumerator();
		}

		IEnumerator IEnumerable.GetEnumerator() {
			return GetEnumerator();
		}

		public override string ToString() {
			StringBuilder builder = new StringBuilder();
			foreach (var value in Datas.Values) {
				builder.AppendJoin(", ", $"{value}");
			}
			return $"{Datas.Values}...";
		}

	}

}